package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzTikutype;
import com.ruoyi.system.service.IDzTikutypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题库类型Controller
 * 
 * @author ruoyi
 * @date 2022-09-06
 */
@RestController
@RequestMapping("/api/tikutype")
public class DzTikutypeApiController extends BaseController
{
    @Autowired
    private IDzTikutypeService dzTikutypeService;

    /**
     * 查询题库类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzTikutype dzTikutype)
    {
        startPage();
        List<DzTikutype> list = dzTikutypeService.selectDzTikutypeListWeb(dzTikutype);
        return getDataTable(list);
    }

    /**
     * 导出题库类型列表
     */
    @Log(title = "题库类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzTikutype dzTikutype)
    {
        List<DzTikutype> list = dzTikutypeService.selectDzTikutypeListWeb(dzTikutype);
        ExcelUtil<DzTikutype> util = new ExcelUtil<DzTikutype>(DzTikutype.class);
        util.exportExcel(response, list, "题库类型数据");
    }

    /**
     * 获取题库类型详细信息
     */
    @GetMapping(value = "/{tlId}")
    public AjaxResult getInfo(@PathVariable("tlId") Long tlId)
    {
        return AjaxResult.success(dzTikutypeService.selectDzTikutypeByTlId(tlId));
    }

    /**
     * 新增题库类型
     */
    @Log(title = "题库类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzTikutype dzTikutype)
    {
        return toAjax(dzTikutypeService.insertDzTikutype(dzTikutype));
    }

    /**
     * 修改题库类型
     */
    @Log(title = "题库类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzTikutype dzTikutype)
    {
        return toAjax(dzTikutypeService.updateDzTikutype(dzTikutype));
    }

    /**
     * 删除题库类型
     */
    @Log(title = "题库类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tlIds}")
    public AjaxResult remove(@PathVariable Long[] tlIds)
    {
        return toAjax(dzTikutypeService.deleteDzTikutypeByTlIds(tlIds));
    }
}
